package cn.edu.jxnu.sse.servlet;

import cn.edu.jxnu.sse.entity.User;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "main",value = "/main")
public class MainServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        String target = "/index.html";
        if(user!=null){
            target = "/WEB-INF/main.html";
        }
        RequestDispatcher disp = request.getRequestDispatcher(target);
        disp.forward(request,response);
       /* String ourMsg = "<html> <head></head><body><H1>" +"<a href='index.html'>请先登录</a>"+
                "<H1/><body/><html/>";
        if(user!=null)
        {
            ourMsg = "<html> <head></head><body><H1>" +"欢迎您,"+user.getUserName()+
                    "<H1/><body/><html/>";
        }
        PrintWriter out = response.getWriter();

        out.println(ourMsg);*/
    }
}
